Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

362 add and edit attributes in sample types #2032

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

kdp-cloud
Copy link
Collaborator

@kdp-cloud kdp-cloud commented Oct 21, 2024

  • Adds possibility to add new optional attribute to an existing sample type
  • Makes the title of a sample attribute editable.
  • If the title of an attribute is updated, the JSON metadata values of all samples that are linked to the sample type are also updated as a background job.

Closes #1257
Closes #1258
Closes #362

@kdp-cloud kdp-cloud marked this pull request as ready for review October 22, 2024 15:40
Copy link
Contributor

@fbacall fbacall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagged a few issues, mostly around concurrency

lib/seek/samples/sample_type_editing_constraints.rb Outdated Show resolved Hide resolved
queue_as QueueNames::SAMPLES

def perform(sample_type, attribute_changes = [], user)
Seek::Samples::SampleMetadataUpdater.new(sample_type, attribute_changes, user).update_metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question, but what happens if someone views a sample before the job has finished running?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to test this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On your local instance you could update a sample type without any workers running. Alternatively, add a sleep here or in the job.

app/views/isa_studies/_sample_types_form.html.erb Outdated Show resolved Hide resolved
lib/seek/samples/sample_type_editing_constraints.rb Outdated Show resolved Hide resolved
lib/seek/samples/sample_metadata_updater.rb Outdated Show resolved Hide resolved

after_action :update_sample_json_metadata, only: :update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if 2 updates were made to a sample type in a short time?

I think you may need a mechanism for "locking" the sample type to further changes until the update job has completed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that was possible. Has it already been done somewhere else in the source code?

metadata = JSON.parse(sample.json_metadata)
# Update the metadata keys with the new attribute titles
@attribute_change_maps.each do |change|
metadata[change[:new_title]] = metadata.delete(change[:old_title])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone creates a new sample before the job finishes, this line will wipe out the changed attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Status: No status
2 participants